import os

FrameworkName = 'TestFramework'

Build_Path = '/Users/liuxing/Documents/SwiftFramework/TestFramework'
DEVICE_DIR='%s/build/Debug-iphoneos/%s.framework'%(Build_Path,FrameworkName)
SIMULATOR_DIR='%s/build/Debug-iphonesimulator/%s.framework'%(Build_Path,FrameworkName)

os.chdir('%s'%Build_Path)
os.system('xcodebuild clean') # delete
os.system('xcodebuild -configuration "Debug" -target %s -sdk iphoneos ARCHS=arm64 ONLY_ACTIVE_ARCH=NO'%(FrameworkName)) # Release
os.system('xcodebuild -configuration "Debug" -target %s -sdk iphonesimulator ARCHS=x86_64 ONLY_ACTIVE_ARCH=YES'%(FrameworkName))

UniversalPath = '%s/Universal/TestFramework.framework'%(Build_Path)
os.system('mkdir -p %s'%(UniversalPath))
os.system('cp -R %s/ %s/'%(DEVICE_DIR,UniversalPath)) # copy device framework

#copy simulator module into iphones module
iphone_module_dir = '%s/Modules/%s.swiftmodule'%(UniversalPath,FrameworkName)
simulator_module_dir = '%s/Modules/%s.swiftmodule'%(SIMULATOR_DIR,FrameworkName)

os.system('cp -R %s/ %s/'%(simulator_module_dir,iphone_module_dir)) # copy simulator module

# lipo create
os.system('lipo -create %s/%s %s/%s -output %s/Universal/TestFramework.framework/%s'%    (DEVICE_DIR,FrameworkName,SIMULATOR_DIR,FrameworkName,Build_Path,FrameworkName))
# os.system('xcodebuild clean')
os.system('open .')